"""
@Author  : 康帅
@Time    : 2021/1/6 15:06
@Function: string
"""


def split_string_data():
    """
    分割字符串数据
    :return:
    """
    str_data = "hello world"
    l_data = """hello , my name is ks"""
    s = '******Hello world******'
    # print(str_data.split())
    print(str_data.split(' '))
    print(str_data.split('  '))
    print(s.strip('*'))

    ss0 = 'hi'
    ss1 = 'h' + 'i'
    join_data = 'hello'
    ss2 = ''.join(join_data)
    print(ss0, ss1, ss2)

    # 常用字符串格式化
    d = 10
    b = 20
    print(f'data is {d} or {b}')
    print("data is {} or {}".format(d, b))
    print("data is {0} or {1}".format(d, b))


def string_to_dict_key_value():
    """
    以字符串值作为key,下标作为value
    :return:
    """
    data = "abc"
    data_dict = {}
    for _, v in enumerate(data):
        data_dict[data[_]] = _
        print(data[_])  # a b c
        print(data_dict[data[_]])  # 0 1 2
    print(data_dict)  # {'a': 0, 'b': 1, 'c': 2}


if __name__ == '__main__':
    split_string_data()
    string_to_dict_key_value()
